package vcp.gui.panels.parkingmanager;

import javax.swing.JLabel;
import javax.swing.JPanel;

import java.awt.BorderLayout;
import java.awt.CardLayout;

import javax.swing.JButton;

import java.awt.FlowLayout;

import javax.swing.border.LineBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;

import db.parking.beans.rates;
import vcp.gui.components.VCPScrollTable;
import vcp.gui.forms.NewRateForm;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class PnlRatesManagement extends JPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 7431401652674550063L;
	private JButton btnNewRate;
	private JButton btnEditRate;
	private JPanel formPanel;
	private JPanel menuPanel;
	private NewRateForm newRateForm;
	private VCPScrollTable ratesTable;
	private CardLayout cardlayout;


	/**
	 * Create the panel.
	 */
	public PnlRatesManagement() {
		newRateForm = getNewRateForm();
		
		setLayout(new BorderLayout(0, 0));
		cardlayout = new CardLayout();
		menuPanel = new JPanel();
		menuPanel.setBorder(new LineBorder(new Color(0, 0, 0)));
		add(menuPanel, BorderLayout.NORTH);
		menuPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
		
		btnNewRate = new JButton("New");
		menuPanel.add(btnNewRate);
		
		btnEditRate = new JButton("Edit");
		menuPanel.add(btnEditRate);
		
		formPanel = new JPanel();
		formPanel.setLayout(cardlayout);
		
	    formPanel.add(getNewRateForm(), "Add");
	    formPanel.add(getRatesTable(), "Edit");
	    //formPanel.add(panel2, "Panel 2");
	   /*
	    ActionListener btnListener = new ActionListener() {	         
			@Override
			public void actionPerformed(ActionEvent arg0) {
				cardlayout.next(formPanel);
			}
	      };
	      */
	   // button1.addActionListener(btnListener);
	   // button2.addActionListener(btnListener);
		
		add(formPanel, BorderLayout.CENTER);

	}
	
	
	public CardLayout getCardlayout() {
		return cardlayout;
	}


	public void setCardlayout(CardLayout cardlayout) {
		this.cardlayout = cardlayout;
	}


	public JButton getBtnNewRate() {
		return btnNewRate;
	}
	public JPanel getFormPanel() {
		return formPanel;
	}
	public void setFormPanel(JPanel formPanel) {
		this.formPanel = formPanel;
	}
	public JPanel getMenuPanel() {
		return menuPanel;
	}
	public void setMenuPanel(JPanel menuPanel) {
		this.menuPanel = menuPanel;
	}
	public void setBtnNewRate(JButton btnNewRate) {
		this.btnNewRate = btnNewRate;
	}
	public JButton getBtnEditRate() {
		return btnEditRate;
	}
	
	
	public NewRateForm getNewRateForm() {
		if(newRateForm==null){
			newRateForm = new NewRateForm();
		}
		return newRateForm;
	}
	
	

	public VCPScrollTable getRatesTable() {
		if(ratesTable==null){
			String header[] = {"Lot number","Rate type","Rate name", "Current rate","Modify rate(Double click)","status"};
			
			DefaultTableModel dtm = new DefaultTableModel(null, header) {
	    		private static final long serialVersionUID = 1L;
	    		@Override
	            public Class<?> getColumnClass(int col) {
	                return getValueAt(0, col).getClass();
	            }
	    	
	            public boolean isCellEditable(int row, int column){  
	                if(column==4)
	                	return true;
	            	return false;  
	            }
	           	           
	        };
			
			ratesTable = new VCPScrollTable(10,dtm);
			
			
			TableColumn column0 = ratesTable.getTable().getColumnModel().getColumn(0);
		    column0.setMinWidth(0);
		    column0.setMaxWidth(0);
		    column0.setWidth(0);
		    column0.setPreferredWidth(0);
		    
		    TableColumn column1 = ratesTable.getTable().getColumnModel().getColumn(1);
		    column1.setMinWidth(0);
		    column1.setMaxWidth(0);
		    column1.setWidth(0);
		    column1.setPreferredWidth(0);
		   

		}
		return ratesTable;
	}


}
